/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.common.json;

import com.entities.Messenger;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

/**
 *
 * @author Tuan Long
 */
public class NotificationJson {

    public static Messenger getMessageFromJsonStr(String json) {
        Messenger mes = new Messenger();
        try {
            JSONParser parser = new JSONParser();
            JSONObject obj = (JSONObject) parser.parse(json);
            String id = obj.get("id").toString();
            String sender = obj.get("sender").toString();
            String content = obj.get("content").toString();
            String recieved = obj.get("recieved").toString();
            String sent = obj.get("sent").toString();
            mes = new Messenger(id, sender, content, sent, recieved);
        } catch (ParseException ex) {
            Logger.getLogger(NotificationJson.class.getName()).log(Level.SEVERE, null, ex);
        }
        return mes;
    }

}
